
import {LLKeyBord} from '@/utils/tools.js'
import {appModelList, modelList} from '@/formgen/components/FormConfig/config.js'
import {
  getRandom
} from "@/api/financeManage/lpay.js";
import {activityPay, setH5Config} from "@/api/activeManage/active";
export default {
  name: "activityPrice", 
  data() {
    return {
      telCode: '',
      LPayProp: {
        options: {},
        passwordInstance: null
      },
    };
  },
  mounted(){
    let _self = this
    // _self.getRandom()
  },
  methods: {
    async getRandom(){
      let _self = this, isSuccess = false
      await getRandom().then(res => {
        _self.LPayProp.options = res.data
        isSuccess = true
      })
      return isSuccess
    },
    initPassword() {
      let _self = this
      setTimeout(() => {
        let paramsPwd = {
          click_objId: '#keyboardBtn',
          Input_texId: '#LOGPASS',
          parent_objId: '#ipt_pwd',
          placeholderId: '#LOGPASS_SHOW'
        }
        const passowrd = LLKeyBord(paramsPwd, _self.LPayProp.options)          
        passowrd.initOptions()
        _self.LPayProp.passwordInstance = passowrd
      })
    },
    async submitDialogPrice(){
      let _self = this
      let {passwordInstance, options} = _self.LPayProp
      let vm = _self.$refs['dialog-price']
      // 获取国密密文
      passwordInstance.setRandKey(options.random_value) // 先设置随机key
      const password = passwordInstance.getOutputSM() // 国密加密密码
      const hash = passwordInstance.getHash() // RSA加密密码
      if(!hash || hash == '') {
        vm.loading = false
        return _self.$message.error('密码不能为空')
      }

      let props = {
        password: password,
        random_key: _self.LPayProp.options['random_key'],
        activityCode: _self.dialogPrice.baseData['activityCode']/*  */
      }
      activityPay(props).then(res => {
        const { code } = res
        if(code == 600){
          _self.$refs['dialog-zhyz'].showDialog = true
        }else{
          vm.showDialog = false
          _self.$message.success('操作成功')
          _self.$router.go(-1)
        }
      }).catch(err => {
        _self.getRandom()
      }).finally(() => {
        vm.loading = false
      })
    },
    // 判断当前活动类型是否只支持h5配置
    hasH5(){
      let {activityTypeId} = this.currentItem, boo = false
      if(activityTypeId == '2' || activityTypeId == '3' || activityTypeId == '4'  || activityTypeId == '7'){
        boo = true
      }
      return boo
    },
    async submitDialogCode(){
      let _self = this
      let vm = _self.$refs['dialog-zhyz']
      if(!_self.telCode || _self.telCode == '') {
        vm.loading = false
        return _self.$message.error('验证码不能为空')
      }

      let props = {
        code: _self.telCode,
        activityCode: _self.dialogPrice.baseData['activityCode']/*  */
      }
      activityPay(props).then(res => {
        vm.showDialog = false
        _self.$message.success('操作成功')
        _self.$router.go(-1)
      }).finally(() => {
        vm.loading = false
      })
    },
  }
};